package com.neusoft.elm.dao.impl;

import com.neusoft.elm.dao.AdminDao;
import com.neusoft.elm.po.Admin;
import com.neusoft.elm.util.DBUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.PreparedStatement;

public class AdminDaoImpl implements AdminDao{
	
	private Connection con =null;
	private ResultSet  rs =null;
	private PreparedStatement pst =null;
	
	@Override
	public Admin getAdmin_Name_Password(String AdminName,String Password) {
		Admin admin = null;
		String sql="select * from Admin where AdminName=? and Password=?";

		try {																	 //管理员登录检测
			con =DBUtil.getConnection();
			pst =con.prepareStatement(sql);
			pst.setString(1, AdminName);
			pst.setString(2, Password);
			rs = pst.executeQuery();
			while(rs.next()) {
				admin = new Admin();
				admin.setAdminID(rs.getInt("AdminID"));
				admin.setAdminName(rs.getString("AdminName"));
				admin.setPassword(rs.getString("Password"));
			}

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {               //释放资源
			DBUtil.close(rs, pst, con);
		}
		return admin;
	}

}
